<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <router-view></router-view>
        <router-link to="/home">主页</router-link>
        <router-link to="/gongsi">公司</router-link>
        <router-link to="/product/123">产品详情1</router-link>
        <router-link to="/product/456">产品详情2</router-link>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script src="./node_modules/vue-router/dist/vue-router.js"></script>
    <script>
        let Home ={
            template:`<h1>主页信息</h1>`
        }
        let routes = [
            {
                path:"/home",
                component:Home
            },
            {
                path:"/gongsi",
                component:()=>Promise.resolve({
                    template:`<h1>公司详情</h1>`,
                    beforeRouteEnter(to,from,next){
                    console.log("组件导航守卫，进入到公司详情的路由");
                    console.log(this);// window 进入之前还不能访问到实例
                    next();
                },
                //路由更新的时候
                beforeRouteUpdate(to,from,next){
                    console.log("组件导航守卫，路由更新的时候");//路由更新时一般用于有id号变更的路由
                    console.log(this);//产品详情组件
                    next();
                },
                //路由离开之前
                beforeRouteLeave(to,from,next){
                    console.log("组件导航守卫离开/gongsi路由");
                    console.log("现在的额路由",from);
                    console.log("前往的路由",to);
                    console.log(this);//离开之前 还没离开this指向实例 产品详情组件
                    next();

    }
                })
            },
            {
                path:"/product/:id",
                component:()=>import("./Product.js")
            }
        ]
        let router =new VueRouter({
            routes
        })
        let vm =new Vue({
            router,
            el:"#app",
        })
    </script>
</body>
</html>